function initpayli() {
    var g = getUrlParms();
    var b = g.name;
    var m = g.price;
    var j = g.tel;
    if (!b || b == "") {
        b = g.aliorder
    }
    if (!m || m == "") {
        m = g.alimoney
    }
    if (!j || j == "") {
        j = g.UserName
    }
    if (b) {
        b = decodeURI(b)
    }
    if (j && j != "") {
        $("#mob").val(j)
    }
    var f = getProductTypeInfo(b, m);
    if (f) {
        var k = 0;
        var a = f.providers;
        var l = "";
        for (var d = 0; d < a.length; d++) {
            var o = a[d];
            var v = "<ul class='pl'>";
            if (f.items[d]) {
                for (var u = 0; u < f.items[d].length; u++) {
                    var r = f.items[d][u];
                    v += '<li id="li_' + k + '"> <div class="provider">' + o + "</div><p>" + r.ver + "</p>";
                    if (r.price != r.sprice) {
                        v += ' <span style="padding-left:5px;text-decoration:line-through;color:#999999">\uffe5' + r.price + "</span>"
                    }
                    v += "<span>\uffe5" + r.sprice + "</span> </li>";
                    var q = "";
                    var e = "";
                    var c = "";
                    if (r.resid) {
                        q = r.resid
                    }
                    if (q == "" && (r.type == "KSBD10101" || r.type == "KSBD10111" || r.type == "KSBD10121" || r.type == "KSBD29101")) {
                        q = "KSBDJSJ" + r.ver.toLowerCase()
                    }
                    if (r.productid) {
                        e = r.productid
                    }
                    if (r.express) {
                        c = r.express
                    }

                    v += '<input type="hidden" id="items_' + k + '" name="items" value="' + k + '"" >';
                    v += '<input type="hidden" id="items_type_' + k + '" value="' + r.type + '">';
                    v += '<input type="hidden" id="items_title_' + k + '" value="' + o + f.name + r.ver + '">';
                    v += '<input type="hidden" id="items_price_' + k + '" value="' + r.price + '">';
                    v += '<input type="hidden" id="items_sprice_' + k + '" value="' + r.sprice + '">';
                    v += '<input type="hidden" id="items_resid_' + k + '" value="' + q + '">';
                    v += '<input type="hidden" id="items_productid_' + k + '" value="' + e + '">';
                    v += '<input type="hidden" id="items_provider_' + k + '" value="' + o + '">';
                    v += '<input type="hidden" id="items_num_' + k + '" value="1">';
                    v += '<input type="hidden" id="items_express_' + k + '" value="' + c + '">';
                    v += '<input type="hidden" id="items_catid_'+ k +'" value="'+r.catid+'">';
                    k++
                }
            }
            v += "</ul>";
            l += "<div class='swiper-slide'>" + v + "</div>"
        }
        $("#payli").append("<div class='swiper-container'><div class='swiper-wrapper'>" + l + "</div></div>")
    }
    var n = setSwiper(a);
    $("#mobclear").click(function () {
        $("#mob").val("")
    });
    $(".pl li").click(function () {
        $(this).toggleClass("curr");
        sumAmount()
    });
    initCurr(f, b, m, n);
    autoSubmitOrder()
}

function autoSubmitOrder() {
}

function setSwiper(b) {
    if (b && b.length > 0) {
        var c = "<table><tr>";
        for (i = 0; i < b.length; i++) {
            c += "<td>" + b[i] + "</td>"
        }
        c += "</tr></table>";
        $(".tab-index").html(c);
        $(".tab-index td").eq(0).addClass("active")
    }
    var a = new Swiper(".swiper-container", {
        onSlideChangeEnd: function (d) {
        }, onSlideChangeStart: function () {
            $(".tab-index .active").removeClass("active");
            $(".tab-index td").eq(a.activeIndex).addClass("active")
        }
    });
    $(".tab-index td").on("touchstart mousedown", function (d) {
        d.preventDefault();
        $(".tab-index .active").removeClass("active");
        $(this).addClass("active");
        a.swipeTo($(this).index())
    });
    return a
}

function initCurr(b, c, d, a) {
    if (d && d.length > 0) {
        $(".pl li").each(function (f) {
            var e = f;
            var k = document.getElementById("items_price_" + e);
            if (d == k.value) {
                $(this).addClass("curr");
                var j = document.getElementById("items_provider_" + e);
                if (b.providers) {
                    var h = b.providers;
                    for (var g = 0; g < h.length; g++) {
                        if (g > 0 && h[g] == j.value) {
                            a.swipeTo(g);
                            break
                        }
                    }
                }
            }
        });
        sumAmount()
    }
}

function ckmob(a) {
    if (a == "") {
        return false
    }
    if (isNaN(a) || (a.length != 11)) {
        return false
    }
    var b = /^0{0,1}(13[0-9]|1[457][0-9]|18[0-9])[0-9]{8}$/;
    if (!b.test(a)) {
        return false
    }
    return true
}

function getItemsParma() {
    var a = "";
    $(".pl li").each(function (g) {
        if ($(this).hasClass("curr")) {
            var l = g;
            a += "&items=" + l;
            var b = document.getElementById("items_type_" + l);
            var h = document.getElementById("items_title_" + l);
            var e = document.getElementById("items_price_" + l);
            var m = document.getElementById("items_sprice_" + l);
            var k = document.getElementById("items_num_" + l);
            var d = document.getElementById("items_express_" + l);
            var j = document.getElementById("items_resid_" + l);
            var f = document.getElementById("items_productid_" + l);
            var c = document.getElementById("items_provider_" + l);
            if (b) {
                a += "&ity_" + l + "=" + b.value
            }
            if (h) {
                a += "&iti_" + l + "=" + encodeURI(h.value)
            }
            if (e) {
                a += "&ipr_" + l + "=" + e.value
            }
            if (m) {
                a += "&isp_" + l + "=" + m.value
            }
            if (k) {
                a += "&inu_" + l + "=" + k.value
            }
            if (d) {
                a += "&iex_" + l + "=" + d.value
            }
            if (j) {
                a += "&iresid_" + l + "=" + j.value
            }
            if (f) {
                a += "&iproductid_" + l + "=" + f.value
            }
            if (c) {
                a += "&iprovider_" + l + "=" + encodeURI(c.value)
            }
        }
    });
    return a
}

function sumAmount() {
    var e = 0;
    var c = 0;
    var f = 0;
    var a = "";
    var b = 0;
    $(".pl li").each(function (l) {
        if ($(this).hasClass("curr")) {
            b++;
            var n = l;
            var m = document.getElementById("items_price_" + n);
            var p = m.value;
            var j = m.value;
            var h = document.getElementById("items_sprice_" + n);
            var o = document.getElementById("items_num_" + n).value;
            var r = document.getElementById("items_title_" + n).value;
            var k = document.getElementById("items_type_" + n).value;
            j = parseFloat(h.value);
            var q = parseFloat(p) * parseInt(o);
            var g = parseFloat(j) * parseInt(o);
            f += q;
            c += g;
            if (b > 1) {
                a += b + "."
            }
            a += r + "\n"
        }
    });
    if (b > 1) {
        a = "1." + a
    }
    var d = f - c;
    document.getElementById("totalfee").value = formatFee(c, 2);
    document.getElementById("totalfeediv").innerHTML = formatFee(c, 2) + "\u5143";
    document.getElementById("totalamount").value = formatFee(f, 2);
    document.getElementById("defee").value = formatFee(d, 2);
    document.getElementById("description").value = a
}

function formatFee(a, b) {
    return Math.round(a * Math.pow(10, b)) / Math.pow(10, b)
}

function checkfrm() {
    if ($("#totalfee").val() == "" || $("#totalfee").val() == "0") {
        alert("\u8bf7\u9009\u62e9\u4e00\u4e2a\u4ea7\u54c1\u7c7b\u578b");
        return false
    }
    if ($("#mob").val() == "") {
        alert("\u8bf7\u8f93\u5165\u60a8\u7684\u624b\u673a\u53f7");
        return false
    }
    if (!ckmob($("#mob").val())) {
        alert("\u624b\u673a\u53f7\u4e0d\u6b63\u786e");
        return false
    }
    return true
}

function createVipPayment(e, a, d, c) {
    var b = "http://vip.100ksw.com/servlet/com.uuoke.payment.action.createPaymentLogJsonpAction";
    b += "?orderNo=" + e;
    b += "&paybank=" + encodeURI(a);
    $.ajax({
        type: "get", async: false, url: b, dataType: "jsonp", jsonp: "jsonpCallback", success: function (f) {
            if (f.code == "SUCCESS") {
                d(f)
            } else {
                c(f.msg)
            }
        }, error: function (f, h, g) {
            c(g)
        }
    })
}

function saveVipOrder(b) {
    var a = "http://vip.100ksw.com/servlet/com.uuoke.payment.action.createOrderJsonpAction";
    a += "?isPaymentLog=" + b.isPaymentLog;
    a += "&accountid=" + b.accountid;
    a += "&ordertype=" + b.ordertype;
    a += "&banktype=" + encodeURI(b.banktype);
    a += "&subject=" + encodeURI(b.subject);
    a += "&tel=" + b.tel;
    a += "&email=" + b.email;
    a += "&openid=" + b.openid;
    a += "&qq=" + b.qq;
    a += "&toAddress=" + encodeURI(b.toAddress);
    a += "&toPerson=" + encodeURI(b.toPerson);
    a += "&description=" + encodeURI(b.description);
    a += "&userMessage=" + encodeURI(b.userMessage);
    a += "&totalfee=" + b.totalfee;
    a += getItemsParma();
    $.ajax({
        type: "get", async: false, url: a, dataType: "jsonp", jsonp: "jsonpCallback", success: function (c) {
            if (c.code == "SUCCESS") {
                b.success(c)
            } else {
                b.error(c.msg)
            }
        }, error: function (c, e, d) {
            b.error(d)
        }
    })
}

function createNativeWxOrder(b, f, e, c, g, a) {
    if (!g || g == "") {
        alert("out_trade_no\u53c2\u6570\u4e0d\u6b63\u786e");
        return
    }
    var d = "http://www.100ksw.net/servlet/com.yihu.wxpay.action.unifiedorderAction";
    d += "?trade_type=NATIVE";
    d += "&body=" + encodeURI(b);
    d += "&detail=" + encodeURI(f);
    d += "&product_id=" + e;
    d += "&total_fee=" + c;
    d += "&out_trade_no=" + g;
    $.ajax({
        type: "GET", async: false, url: d, dataType: "jsonp", jsonp: "jsonpCallback", success: function (h) {
            if (h.return_code == "SUCCESS") {
                a(h)
            } else {
                if (h.return_code == "FAIL") {
                    alert("\u5fae\u4fe1\u7edf\u4e00\u4e0b\u5355\u5931\u8d25\uff1a" + h.return_msg)
                }
            }
        }, error: function (h, k, j) {
            if (k != "200") {
                alert("\u5fae\u4fe1\u7edf\u4e00\u4e0b\u5355\u8bf7\u6c42\u5931\u8d25(" + k + ")")
            }
        }
    })
}

function createJsapiWxOrder(h, b, f, e, c, g, a) {
    if (!isWeixin()) {
        alert("\u5f53\u524d\u73af\u5883\u4e0d\u652f\u6301\u5fae\u4fe1\u652f\u4ed8,\u8bf7\u4f7f\u7528\u5176\u5b83\u65b9\u5f0f\u8d2d\u4e70\u3002");
        return
    }
    if (!h || h == "") {
        alert("openid \u53c2\u6570\u4e0d\u6b63\u786e");
        return
    }
    var d = "http://www.100ksw.net/servlet/com.yihu.wxpay.action.unifiedorderAction";
    d += "?openid=" + h;
    d += "&trade_type=JSAPI";
    d += "&body=" + encodeURI(b);
    d += "&detail=" + encodeURI(f);
    d += "&product_id=" + e;
    d += "&total_fee=" + c;
    d += "&out_trade_no=" + g;
    $.ajax({
        type: "GET", async: false, url: d, dataType: "jsonp", jsonp: "jsonpCallback", success: function (k) {
            if (k.return_code == "SUCCESS") {
                var l = k.appId;
                var j = k.timeStamp;
                var m = k.nonceStr;
                var o = k.prepaypackage;
                var n = k.paySign;
                jsApiCall(l, j, m, o, n, a)
            } else {
                if (k.return_code == "FAIL") {
                    alert("\u5fae\u4fe1\u7edf\u4e00\u4e0b\u5355\u5931\u8d25\uff1a" + k.return_msg)
                }
            }
        }, error: function (j, l, k) {
            if (l != "200") {
                alert("\u5fae\u4fe1\u7edf\u4e00\u4e0b\u5355\u8bf7\u6c42\u5931\u8d25(" + l + ")")
            }
        }
    })
}

function jsApiCall(c, b, d, f, e, a) {
    WeixinJSBridge.invoke("getBrandWCPayRequest", {
        appId: c,
        timeStamp: b,
        nonceStr: d,
        "package": f,
        signType: "MD5",
        paySign: e
    }, a)
};
